package com.fang.modbus.example;

import java.util.logging.Level;
import java.util.logging.Logger;

import com.fang.modbus.ModbusClient;
import com.fang.modbus.ModbusServer;
import com.fang.modbus.exception.ModbusException;
import com.fang.modbus.struct.ModbusFrame;
import com.fang.modbus.struct.tcp.ModbusTCPFrameFactory;

/**
 * 简单测试
 * @author James
 * @version 1.0
 * @since 2018年11月13日
 *
 */
public class ModbusExample 
{
    public static void main(String[] args) 
    {
        ModbusServer modbusServer = ModbusServerSingleton.getInstance().getModbusServer();
        ModbusClient modbusClient = ModbusClientSingleton.getInstance().getModbusClient();
        
        ModbusFrame readCoils = null;
        try {
            readCoils = modbusClient.send(ModbusTCPFrameFactory.readCoil(12321, 10));
        } catch (ModbusException ex) {
            Logger.getLogger(ModbusExample.class.getName()).log(Level.SEVERE, ex.getLocalizedMessage());
        }
        System.out.println(readCoils);

        modbusClient.shutdown();
        modbusServer.shutdown();
    }
}
